package process

import (
	"context"
	"gitee.com/alex_li/amazon-rpt/cmd/rpt/process/bid"
	"gitee.com/alex_li/amazon-rpt/cmd/rpt/process/common"
	"gitee.com/alex_li/amazon-rpt/cmd/rpt/process/rpt"
	"github.com/lishimeng/app-starter/broker"
)

func Setup(ctx context.Context) (err error) {

	go func() {
		//profile.UpdateProfiles(ctx)
	}()

	//rptProc(ctx)
	bidProc(ctx)

	bid.SyncSbKeywords(ctx)

	//err = schedule.Setup(ctx)
	//if err != nil {
	//	return
	//}
	return
}

func bidProc(ctx context.Context) {

	// 同步活动
	broker.Get().Subscribe(common.TaskSyncCampaign, func(item broker.MessageItem) {
		bid.SyncCampaigns(ctx)
	})
	// 同步keyword
	broker.Get().Subscribe(common.TaskSyncKeyword, func(item broker.MessageItem) {
		bid.SyncKeywords(ctx)
	})
	// 更新keyword
	broker.Get().Subscribe(common.TaskUpdateKeyword, func(item broker.MessageItem) {
		bid.UpdateKeywords(ctx)
	})
}

func rptProc(ctx context.Context) {
	go func() {
		rpt.Schedule(ctx)
	}()
	go func() {
		rpt.SubmitRpt(ctx)
	}()
	go func() {
		rpt.UpdateRpt(ctx)
	}()
	go func() {
		rpt.DownloadRptFile(ctx)
	}()
	go func() {
		rpt.HandleRptFile(ctx)
	}()
}
